              package com.java.diagnostics.visualizer.impl.properties;
              
              import com.java.diagnostics.visualizer.impl.GCAndMemoryVisualizerImplPreferenceInitalizer;
              import com.java.diagnostics.visualizer.impl.extensions.DisplayerRegistry;
              import com.java.diagnostics.visualizer.impl.extensions.GCAndMemoryVisualizerExtensionRegistry;
              import com.java.diagnostics.visualizer.impl.extensions.ParserRegistry;
              import com.java.diagnostics.visualizer.impl.extensions.PostProcessorRegistry;
              import com.java.diagnostics.visualizer.impl.preferences.GCAndMemoryVisualizerPreferenceInitializer;
              import com.java.diagnostics.visualizer.impl.preferences.PreferencesImportListener;
              import com.java.diagnostics.visualizer.impl.preferences.SmartPreferences;
              import com.java.diagnostics.visualizer.properties.ExtensionEnablementProperties;
              import java.util.HashSet;
              import java.util.Iterator;
              import java.util.Set;
              import org.eclipse.core.runtime.IConfigurationElement;
              import org.eclipse.core.runtime.IExtension;
              //import org.eclipse.core.runtime.Platform;
              import org.osgi.service.prefs.Preferences;
              
              public class ExtensionEnablementPropertiesImpl
                implements ExtensionEnablementProperties, PreferencesImportListener
              {
                private static final String SPLITTING_REGEX = "[\\[, \\]]";
                private static final String COMMA = ", ";
                private static final String CLOSE_BRACKET = "]";
                private static final String OPEN_BRACE = "[";
                private Set extensionEnablements = null;
                protected static final String CLASS = "class";
                private SmartPreferences preferences;
                private String key;
                private static ExtensionEnablementProperties displayerEnablementProperties;
                private static ExtensionEnablementProperties parserEnablementProperties;
                private static ExtensionEnablementProperties postprocessorEnablementProperties;
              
                public static ExtensionEnablementProperties getDisplayerEnablementProperties()
                {
                  if (displayerEnablementProperties == null) {
                    displayerEnablementProperties = new ExtensionEnablementPropertiesImpl(
                      DisplayerRegistry.getInstance());
                  }
                  return displayerEnablementProperties;
                }
              
                public static ExtensionEnablementProperties getParserEnablementProperties()
                {
                  if (parserEnablementProperties == null) {
                    parserEnablementProperties = new ExtensionEnablementPropertiesImpl(
                      ParserRegistry.getInstance());
                  }
                  return parserEnablementProperties;
                }
              
                public static ExtensionEnablementProperties getPostprocessorEnablementProperties()
                {
                  if (postprocessorEnablementProperties == null) {
                    postprocessorEnablementProperties = new ExtensionEnablementPropertiesImpl(
                      PostProcessorRegistry.getInstance());
                  }
                  return postprocessorEnablementProperties;
                }
              
                public static void initializeDefaults(Preferences preferences) {
                  initializeDefaults(preferences, ParserRegistry.getInstance());
                  initializeDefaults(preferences, PostProcessorRegistry.getInstance());
                  initializeDefaults(preferences, DisplayerRegistry.getInstance());
                }
              
                public ExtensionEnablementPropertiesImpl(GCAndMemoryVisualizerExtensionRegistry registry)
                {
/*  80 *///          if (Platform.isRunning())
/*     *///          {
/*  83 *///            this.key = constructKey(registry);
/*  84 *///            this.preferences = 
/*  85 *///              GCAndMemoryVisualizerImplPreferenceInitalizer.getInstance().getPreferences();
/*  86 *///            refreshFromPreferences();
/*  87 *///            this.preferences.addPreferenceListener(this);
/*     *///          } else {
                    this.extensionEnablements = new HashSet();
                 // }
                }
              
                private void refreshFromPreferences()
                {
                  String values = this.preferences.getString(this.key);
                  this.extensionEnablements = destringify(values);
                }
              
                private static String constructKey(GCAndMemoryVisualizerExtensionRegistry registry) {
                  if (registry != null)
                  {
                    return registry.getClass().getName() + ".v1";
                  }
                  return null;
                }
              
                protected static String stringify(Set set) {
                  StringBuffer buffer = new StringBuffer();
                  buffer.append("[");
                  Iterator it = set.iterator();
                  while (it.hasNext()) {
                    buffer.append(it.next());
                    if (it.hasNext()) {
                      buffer.append(", ");
                    }
                  }
                  buffer.append("]");
              
                  return buffer.toString();
                }
              
                protected Set destringify(String string)
                {
                  Set set = new HashSet();
                  if (string.length() > 0) {
                    String[] split = string.split("[\\[, \\]]");
                    for (int i = 0; i < split.length; i++)
                    {
                      String extensionName = split[i].trim();
                      if (extensionName.length() > 0) {
                        set.add(extensionName);
                      }
                    }
                  }
              
                  return set;
                }
              
                public void enableExtension(String extensionId) {
                  this.extensionEnablements.add(extensionId);
                  updatePreferences();
                }
              
                public void disableExtension(String extensionId)
                {
                  this.extensionEnablements.remove(extensionId);
                  updatePreferences();
                }
              
                public boolean isExtensionEnabled(String extensionId) {
                  return this.extensionEnablements.contains(extensionId);
                }
              
                private void updatePreferences()
                {
                  if (this.preferences != null) {
                    String string = stringify(this.extensionEnablements);
                    this.preferences.setValue(this.key, string);
                  }
                }
              
                public void preferenceChange() {
                  refreshFromPreferences();
                }
              
                public void addPreferencesListener(PreferencesImportListener listener)
                {
                  this.preferences.addPreferenceListener(listener);
                }
              
                public static void initializeDefaults(Preferences defaults, GCAndMemoryVisualizerExtensionRegistry registry)
                {
                  Set extensionEnablements = new HashSet();
                  if (registry != null) {
                    IExtension[] extensions = registry.getExtensions();
                    if (extensions != null) {
                      for (int i = 0; i < extensions.length; i++) {
                        IConfigurationElement configuration = extensions[i]
                          .getConfigurationElements()[0];
                        String extensionId = configuration.getAttribute("class");
                        boolean onByDefault = Boolean.valueOf(
                          configuration.getAttribute("enabledByDefault"))
                          .booleanValue();
                        if (onByDefault) {
                          extensionEnablements.add(extensionId);
                        }
                      }
                    }
                  }
                  String value = stringify(extensionEnablements);
                  defaults.put(constructKey(registry), value);
                }
              }

